package com.igeek.compus.backend.system;

import lombok.Data;

@Data
public class R<T> {
    private Integer code;
    private Integer count;
    private String msg;
    private T data;

    public R() {
    }

    private R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static R success(Object data) {
        return new R(Constants.SUCCESS_CODE, Constants.SUCCESS_MSG, data);
    }

    public static R success() {
        return success((Object)null);
    }

    public static R fail(Object data) {
        return new R(Constants.SUCCESS_CODE, Constants.SUCCESS_MSG, data);
    }


    public static R fail(String message) {
        return new R(Constants.FAIL_CODE, message);
    }

    public static R error() {
        return new R(Constants.ERROR_CODE, "系统异常");
    }

}
